package cn.hesion.outputformat;
/**
 * ClassName: OutputFormatDriver <br/>
 * Description: <br/>
 * date: 2021/2/3 19:23<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @program: ClientDemo
 * @description:
 * @author: hesion
 * @create: 2021-02-03 19:23
 **/
public class OutputFormatDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        final Configuration conf = new Configuration();
        final Job job = Job.getInstance(conf);
        job.setJarByClass(OutputFormatDriver.class);
        job.setMapperClass(OutputMapper.class);
        job.setReducerClass(OutputReducer.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);
        job.setOutputFormatClass(CustomOutputFormat.class);

        FileInputFormat.setInputPaths(job, new Path("D:\\大数据学习\\大数据正式班第一阶段模块一\\模块一\\资料\\data\\click_log\\click_log.data"));
        // outputformat继承自fileoutputformat 而fileoutputformat要输出一个_SUCCESS        文件，所以，在这还得指定一个输出目录
        FileOutputFormat.setOutputPath(job, new Path("d:/click_log/output"));
        final boolean flag = job.waitForCompletion(true);
        System.exit(flag ? 0 : 1);
    }
}
